<template>
  <!-- hidden PageHeaderWrapper title demo -->
  <page-header-wrapper :title="false">
    <a-card :body-style="{ padding: '24px 32px' }" :bordered="false">
      <a-alert
        type="error"
        message="本功能将分类1合并到分类2，合并之后，分类1消失，原分类1的所有商品全部修改为分类2。请谨慎操作，该功能不可恢复。"
      />
      <a-form @submit="handleSubmit" :form="form" style="margin-top: 24px">
        <a-form-item
          label="分类1"
          :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
          :wrapperCol="{ lg: { span: 10 }, sm: { span: 17 } }"
        >
          <a-select v-decorator="['class1']" placeholder="请选择分类" >
            <a-select-option :value="i.id" v-for="i in option" :key="i.id">{{ i.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          label="分类2"
          :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
          :wrapperCol="{ lg: { span: 10 }, sm: { span: 17 } }"
        >
          <a-select v-decorator="['class2']" placeholder="请选择分类" >
            <a-select-option :value="i.id" v-for="i in option" :key="i.id">{{ i.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item :wrapperCol="{ span: 24 }" style="text-align: center">
          <a-button htmlType="submit" type="primary" icon="check">提交</a-button>
          <!-- <a-button style="margin-left: 8px">{{ $t('form.basic-form.form.save') }}</a-button> -->
        </a-form-item>
      </a-form>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { mergeGdClassUsingPOST, getGdClassListUsingPOST } from '@/api/api/shangpinguanli.ts'
export default {
  name: 'GoodsClassifyMerge',
  data() {
    return {
      form: this.$form.createForm(this),
      option: [],
      optionParam: {
        pageNo: 1,
        pageSize: 999,
        queryCondition: '',
        status: 1,
      },
    }
  },
  mounted() {
    this.getOption()
  },
  methods: {
    getOption() {
      getGdClassListUsingPOST(this.optionParam)
        .then((res) => {
          this.option = res.data.list
        })
        .catch((error) => {
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
    },
    // handler
    handleSubmit(e) {
      e.preventDefault()
      this.form.validateFields((err, values) => {
        if (!err) {
          mergeGdClassUsingPOST({ ...values })
            .then(() => {
              this.$message.success('操作成功')
              this.$router.back()
              // 重置表单数据
              this.form.resetFields()
            })
            .catch((error) => {
              this.confirmLoading = false
              this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
            })
        }
      })
    },
  },
}
</script>
